package main

import (
	"fmt"
	"leetcode/tree/common"
)

func diameterOfBinaryTree(root *common.TreeNode) int {
	return dfs(root)
}

func dfs(node *common.TreeNode) int {
	if node == nil {
		return 0
	}
	leftMaxDia := dfs(node.Left)
	rightMaxDia := dfs(node.Right)
	return max(leftMaxDia, rightMaxDia) + 1
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	arr := []string{"1", "2", "3", "4", "5"}
	root := common.DeSerializeBFS(arr)
	common.MidWalk(root)
	fmt.Println(diameterOfBinaryTree(root))
}
